﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using System.Data;

namespace Tigera.DBFParser
{    
    public class DBFReader
    {
        
        //读取深圳交易所的
        public static DataSet ReadSJSHQ(string fpath)
        {
            string strConn = @"Provider=vfpoledb;Data Source=" + fpath  + ";Collating Sequence=machine;";
            using (OleDbConnection myConnection = new OleDbConnection(strConn))
            {
                OleDbDataAdapter adpt = new OleDbDataAdapter("select * from 20121210091343_show2003", myConnection);
                DataSet mySet = new DataSet();
                adpt.Fill(mySet);
                myConnection.Close();
                return mySet;
            }
        }

        //对于上交所的dbf文件，其数据前200多行格式上处于删除状态，隐藏需要把其恢复的读取
        public static DataSet ReadShow2003S1(string fpath)
        {
            string strConn = @"Provider=vfpoledb;Data Source=" + fpath + ";Collating Sequence=machine;";
            using (OleDbConnection myConnection = new OleDbConnection(strConn))
            {
                myConnection.Open();
                OleDbCommand cmd = new OleDbCommand();
                cmd.Connection = myConnection;
                cmd.CommandText = "SET DELETED OFF";//去掉删除标记，拿到所有记录 
                cmd.CommandType = CommandType.Text;
                cmd.ExecuteNonQuery();
                OleDbDataAdapter adpt = new OleDbDataAdapter("select s1 from show2003.dbf", myConnection);
                DataSet mySet = new DataSet();
                adpt.Fill(mySet);
                myConnection.Close();
                return mySet;
            }
        }


    }
}
